package com.ysc.IUDS;

import com.ysc.domain.Student;
import com.ysc.utils.mybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Scanner;

public class Student_Information {

    private static int TOP_Stid;

    public static int GetTopStid(){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlId = "com.ysc.Dao.StudentDao.getMaxStid";
        TOP_Stid = sqlSession.selectOne(SqlId);
        sqlSession.close();
        return TOP_Stid;
    }

    public static void StudentShow(){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlId = "com.ysc.Dao.StudentDao.selectStudent";
        Scanner in = new Scanner(System.in);
        int Sid = in.nextInt();
        Student stu = new Student();
        stu.setStid(Sid);
        Student student1 = sqlSession.selectOne(SqlId,stu);
        System.out.println(student1);
        sqlSession.close();
    }

    public static void GetSname(int Stid){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlId = "com.ysc.Dao.StudentDao.GetSname";
        Student stu = new Student();
        stu.setStid(Stid);
        String Sname = sqlSession.selectOne(SqlId,stu);
        System.out.println(Sname);
        sqlSession.close();
    }

    public static int StudentInsert(){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String Sqlid = "com.ysc.Dao.StudentDao.insertStudent";
        TOP_Stid = TOP_Stid+1;

        Scanner in = new Scanner(System.in);
        Student stu = new Student();
        System.out.println("姓名：");
        stu.setSname(in.next());
        System.out.println("年龄：");
        stu.setSage(in.nextInt());
        System.out.println("报名时间（今天）：");
        stu.setApplyTime(in.next());
        System.out.println("您的学号是"+TOP_Stid);
        stu.setStid(TOP_Stid);
        int Num = sqlSession.insert(Sqlid,stu);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(Num + "个学生信息已录入，请继续填报账户信息并缴费。");
        return TOP_Stid;
    }

}
